package com.jrx.anytxn.transaction.service.impl;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.number.exception.SegmentException;
import com.jrx.anytxn.number.service.ISegmentService;
import com.jrx.anytxn.param.constant.ErrorMsgConstant;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.AmLoanAccountInfo;
import com.jrx.anytxn.transaction.entity.BtAccountingTransferList;
import com.jrx.anytxn.transaction.service.IBtAccountingTransferListService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: anytxn-cf-transaction
 * @description: 会计状态待处理服务实现类
 * @author: xiaoyu.jing
 * @date: 2019-11-16 17:00
 **/
@Service
public class BtAccountingTransferListServiceImpl implements IBtAccountingTransferListService {

    private static final Logger logger = LoggerFactory.getLogger(BtAccountingTransferListServiceImpl.class);

    @Autowired
    private ISegmentService segmentService;

    /**
     * 构建会计状态转列待处理列表
     * @param amLoanAccountInfo
     * @param bussinessDate
     * @return
     * @throws TxnBizException
     */
    @Override
    public BtAccountingTransferList build(AmLoanAccountInfo amLoanAccountInfo, Date bussinessDate) throws TxnBizException {
        BtAccountingTransferList transferList = new BtAccountingTransferList();
        BeanMapping.copy(amLoanAccountInfo,transferList);
        try {
            transferList.setId(segmentService.getId(TransBizConstant.BT_ACCOUNTING_TRANSFER_LIST_ID));//id
        } catch (SegmentException e) {
            logger.error("主键生成错误", e);
            throw new TxnBizException(TxnRespCode.ERROR.getUserTips());
        }
        transferList.setBusinessDate(bussinessDate);
        transferList.setUpdateBy(TransBizConstant.SYS_OPRATE);
        transferList.setCreateTime(null);
        transferList.setUpdateTime(null);
        return transferList;
    }
}
